*12-09-24_loop_mi_robustness_bdm.do

clear
macro drop _all

global filetree /Users/Allan/Dropbox/!!Papers/Liberal Peace/12-02-21_ISQ_commentary/DOR_ISQ_2013_Replication/M_Rep

cd "$filetree"
use "midata"

mi xtset, clear

**check that logit runs with midyears*
sort ccode1 ccode2 year
global controls lncprt mjpw contigl lndist numstate

gen specification="NA"
gen specnumber=.
gen n=.
gen bdmCoefficient=.
gen bdmSE=.
gen CIElCoefficient=.
gen CIElSE=.
gen bdmpvalues=.
gen CIElpvalues=.


gen bdm=.
replace bdm=1 if dml>6 & dml<11
replace bdm=0 if dml<=6 & dml>=-10 

mi passive: generate bdmCIElc= bdm*CIElc

gen h10dm=.
replace h10dm=1 if dml>9 & dml<11
replace h10dm=0 if dml<=9 & dml>=-10 

mi passive: generate h10dmCIElc= h10dm*CIElc

**Code just to see if things are running
mi estimate, dots: logit fmidonsl lnlifedeerl bdm $controls fmidyears*, cl(dyadid) 
logit midonsl _1_lnlifedeerl bdm $controls	 midyears*, cl(dyadid) 
logit midonsl _2_lnlifedeerl bdm $controls	 midyears*, cl(dyadid) 
logit fmidonsl _3_lnlifedeerl bdm $controls	 fmidyears*, cl(dyadid) nolog
****

sort ccode1 ccode2 year

local j=0

**M2 m.i. with 4 dependent variables x interaction = 8 models
local j=`j'+1
local spec`j' "M'"
local covars`j' "midonsl CIEl  bdm 					   $controls midyears*"


local j=`j'+1
local spec`j' "OM'"
local covars`j' "midongl CIEl  bdm 					   $controls midyears*"


local j=`j'+1
local spec`j' "FM'"
local covars`j' "fmidonsl CIEl  bdm 					   $controls fmidyears*"


local j=`j'+1
local spec`j' "FOM'"
local covars`j' "fmidongl CIEl  bdm 					   $controls fmidyears*"

local j=`j'+1
local spec`j' "IM'"
local covars`j' "midonsl CIElc  bdm bdmCIElc 					   $controls midyears*"


local j=`j'+1
local spec`j' "OIM'"
local covars`j' "midongl CIElc  bdm 	 bdmCIElc 				   $controls midyears*"


local j=`j'+1
local spec`j' "FIM'"
local covars`j' "fmidonsl CIElc  bdm 		 bdmCIElc 			   $controls fmidyears*"


local j=`j'+1
local spec`j' "FOIM'"
local covars`j' "fmidongl CIElc  bdm  	bdmCIElc 				   $controls fmidyears*"



**M2 m.i. with DemocracyHigh with 4 dependent variables x interaction = 8 models


**M2 with 4 dependent variables x interaction = 8 models
local j=`j'+1
local spec`j' "DM'"
local covars`j' "midonsl CIEl  bdm  dmh 					   $controls midyears*"


local j=`j'+1
local spec`j' "ODM'"
local covars`j' "midongl CIEl  bdm  dmh 					   $controls midyears*"


local j=`j'+1
local spec`j' "FDM'"
local covars`j' "fmidonsl CIEl  bdm  dmh 					   $controls fmidyears*"


local j=`j'+1
local spec`j' "FODM'"
local covars`j'  "fmidongl CIEl  bdm  dmh					   $controls fmidyears*"


local j=`j'+1
local spec`j'  "IDM'"
local covars`j'  "midonsl CIElc  bdm bdmCIElc 	 dmh 				   $controls midyears*"


local j=`j'+1
local spec`j'  "OIDM'"
local covars`j'  "midongl CIElc  bdm 	 bdmCIElc 	 dmh 			   $controls midyears*"


local j=`j'+1
local spec`j'  "FIDM'"
local covars`j'  "fmidonsl CIElc  bdm 		 bdmCIElc 	 dmh 		   $controls fmidyears*"


local j=`j'+1
local spec`j'  "FOIDM'"
local covars`j' "fmidongl CIElc  bdm  	bdmCIElc 	 dmh 			   $controls fmidyears*"




****With other measures of life insurance expenditures


**M2 m.i. with 4 dependent variables x interaction = 8 models
local j=`j'+1
local spec`j' "L'"
local covars`j' "midonsl lnlifepenl  bdm 					   $controls midyears*"


local j=`j'+1
local spec`j' "OL'"
local covars`j' "midongl lnlifepenl  bdm 					   $controls midyears*"


local j=`j'+1
local spec`j' "FL'"
local covars`j' "fmidonsl lnlifepenl  bdm 					   $controls fmidyears*"


local j=`j'+1
local spec`j' "FOL'"
local covars`j' "fmidongl lnlifepenl  bdm 					   $controls fmidyears*"

local j=`j'+1
local spec`j' "IL'"
local covars`j' "midonsl CIElc  bdm bdmCIElc 					   $controls midyears*"


local j=`j'+1
local spec`j' "OIL'"
local covars`j' "midongl CIElc  bdm 	 bdmCIElc 				   $controls midyears*"


local j=`j'+1
local spec`j' "FIL'"
local covars`j' "fmidonsl CIElc  bdm 		 bdmCIElc 			   $controls fmidyears*"


local j=`j'+1
local spec`j' "FOIL'"
local covars`j' "fmidongl CIElc  bdm  	bdmCIElc 				   $controls fmidyears*"



**M2 m.i. with DemocracyHigh with 4 dependent variables x interaction = 8 models

local j=`j'+1
local spec`j' "DL'"
local covars`j' "midonsl lnlifepenl  bdm  dmh 					   $controls midyears*"


local j=`j'+1
local spec`j' "ODL'"
local covars`j' "midongl lnlifepenl  bdm  dmh 					   $controls midyears*"


local j=`j'+1
local spec`j' "FDL'"
local covars`j' "fmidonsl lnlifepenl  bdm  dmh 					   $controls fmidyears*"


local j=`j'+1
local spec`j' "FODL'"
local covars`j'  "fmidongl lnlifepenl  bdm  dmh					   $controls fmidyears*"


local j=`j'+1
local spec`j'  "IDL'"
local covars`j'  "midonsl CIElc  bdm bdmCIElc 	 dmh 				   $controls midyears*"


local j=`j'+1
local spec`j'  "OIDL'"
local covars`j'  "midongl CIElc  bdm 	 bdmCIElc 	 dmh 			   $controls midyears*"


local j=`j'+1
local spec`j'  "FIDL'"
local covars`j'  "fmidonsl CIElc  bdm 		 bdmCIElc 	 dmh 		   $controls fmidyears*"


local j=`j'+1
local spec`j'  "FOIDL'"
local covars`j' "fmidongl CIElc  bdm  	bdmCIElc 	 dmh 			   $controls fmidyears*"


sort ccode1 ccode2 year

**Estimating Models, Saving Values
forvalues k=1(1)`j' {
replace specification="`spec`k''" if _n==`k'
mi estimate, dots: logit `covars`k'', cl(dyadid) nolog
replace n= e(N)   if _n==`k'
mat A=e(b_mi)
mat V=e(V_mi)
replace specnumber=`k' if _n==`k'
replace bdmCoefficient=A[1,2] if _n==`k'
replace bdmSE=(V[2,2])^(1/2) if _n==`k'
replace CIElCoefficient=A[1,1] if _n==`k'
replace CIElSE=(V[1,1])^(1/2) if _n==`k'

}


order specification specnumber n bdmCoefficient bdmSE bdmpvalues CIElCoefficient CIElSE CIElpvalues
replace bdmpvalues=2*normal(-abs(bdmCoefficient/bdmSE))
replace CIElpvalues=2*normal(-abs(CIElCoefficient/CIElSE))
keep specification specnumber n bdmCoefficient bdmSE bdmpvalues CIElCoefficient CIElSE CIElpvalues
drop if specnumber==.

saveold "robustnessMbdm.dta", replace




